<template>
    <eui-base-card v-for="(item, index) in pointsData" :title="item.c_point_id" :key="index" :titleLine="true">
        <template #right>
            <eui-tag v-show="!(showdata?.filter(t => t.c_point_id == item.c_point_id).length>0)" text="暂无数据" :showBorder="false" plain plainFill> </eui-tag>
        </template>
        <eui-base-card v-for="(pitem, pindex) in showdata?.filter(t => t.c_point_id == item.c_point_id)" :key="pindex">

            <eui-card-input v-model="pitem.c_value" :range="pitem?.c_option_list" :title="pitem?.c_title"
                :type="pitem.c_input_type" :displayable="pitem.c_displayable" />

            <eui-card-input v-model="pitem.c_abnormal" title="是否异常" type="switch" :displayable="pitem.c_displayable" />

            <eui-card-input v-show="pitem.c_is_abnormal == '1'" v-model="pitem.c_rectify_memo" title="整改说明"
                type="textarea" placeholder="请录入整改说明" maxlength="200" :displayable="pitem.c_displayable" />

            <eui-card-input v-if="item.c_work_status >= '5' && pitem.c_abnormal " v-model="pitem.c_recheck"
                title="复检完成" type="switch" :displayable="pitem.c_displayable" />

            <eui-card-input v-if="item.c_work_status >= '5' && pitem.c_abnormal "
                v-model="pitem.c_recheck_memo" title="复检说明" type="textarea" placeholder="请录入复检说明" maxlength="200"
                :displayable="pitem.c_displayable" />
        </eui-base-card>
        <view class="ml-15">
            <UploadFile :autoUpload="false" :disabled=true :readonly=true fileMediatype="image"
                        :fileId="item.c_id+'-'+item.c_point_id" fileClass="巡检任务单" return-type="array" mode="grid">
            </UploadFile>
        </view>
    </eui-base-card>
</template>

<script setup lang="ts">
import { computed, inject } from 'vue';
import UploadFile from '@/components/UploadFile.vue';

const pointsData = inject('patrolWorkbenchPointsData');
const resultsData = inject('patrolWorkbenchResultsData');
const itemData = inject('patrolWorkbenchItemsData');

console.log('pointsData', pointsData);

const showdata = computed(() => {
    const data = resultsData?.value?.map(item => {
        const curItem = itemData?.value?.datas.find(i => i.c_item_id == item.c_item_id)
        return {
            ...item,
            c_title: curItem?.c_title,
            c_option_list: curItem?.c_option_list?.map(ci => {
                return {
                   ...ci,
                   checked: item?.c_value.includes(ci.value)? true : false
                }
            }),
            c_displayable: true,
            c_abnormal: item?.c_is_abnormal == '1' ? true : false,
            c_input_type: curItem?.c_input_type,
            c_recheck: item?.c_is_recheck == '1' ? true : false,
        }
    });
    return data
})

</script>

<style lang="scss" scoped>
::v-deep .m-card {
    &-radio-view {
        padding: 0 !important;
    }
    &-input-view {
        padding: 28rpx 0 !important;
    }
}

.ml-15 {
    margin-left: 15rpx;
}

::v-deep .e-card__content {
    margin-left: 10rpx ;
}

::v-deep .e-card__title {
    margin-left: 20rpx ;
}
</style>